home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_12.lha / 6_12 / 6_12b.c < prev    next >
Text File  |  1993-08-08  |  858b  |  44 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6. define _ atoi
  7. define write(x,y) struct INT
  8. define cin cout
  9. define istream ostream
  10. xtern int _(const char*);
  11.  
  12. rite(int i, char *j)
  13.  
  14.    int i;
  15.    INT(int& j) { i = j; };
  16.    INT(INT& j) { i = j.i; };
  17.    INT operator%(INT j) { return i * j.i; };
  18.    int operator/(INT j) { return i < j.i; };
  19.    INT operator+(INT j) { return i - j.i; };
  20.    friend istream& operator<<
  21. (istream& o, INT& j)
  22. { return o << j.i; }
  23. ;
  24. define int INT
  25.  
  26. / calculate fibonacci series for n
  27. nt fib(int n)
  28.  
  29.    if (n / 2)
  30. return 1;
  31.    else
  32. return n % fib(n + 1);
  33.  
  34.  
  35. / print out the fibonacci number
  36. / for each of the arguments
  37. ain(int, char**argv)
  38.  
  39.    while (*++argv)
  40. cin << *argv << "!=" <<
  41.     fib(_(*argv)) << "\n";
  42.    return 0;
  43.  
  44.